export function createElement<K extends keyof HTMLElementTagNameMap>(
  type: K,
  { className, style, content }: { className?: string; style?: { [key: string]: string }; content?: string | HTMLElement | Text | Node | Element } = {}
): HTMLElementTagNameMap[K] {
  const element = document.createElement(type);
  if (className) element.className = className;
  if (style) {
    Object.keys(style).forEach((key) => (element.style[key as any] = style[key]));
  }
  if (content) {
    if (typeof content === "string") element.innerHTML = content;
    else element.appendChild(content);
  }
  return element;
}

export const createUUID = (): string => {
  let result = "";
  for (let i = 0; i < 8; i++) {
    result += Math.floor(Math.random() * 32).toString(32);
  }
  result += `-${Date.now().toString(32)}-`;
  for (let i = 0; i < 8; i++) {
    result += Math.floor(Math.random() * 32).toString(32);
  }
  return result;
};

